import axios from 'axios';
import { history, useLocation } from 'umi';
import { message } from 'antd';
import { logout } from '@/service/logout';
const service = axios.create({
  baseURL: '/api-miner/v1',
  timeout: 5000, // request timeout
  headers: {
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,fr;q=0.7',
    'client-type': 'web',
    lang: 'zh',
  },
});

service.interceptors.response.use(
  (response) => {
    if (response.data && response.data.code) {
      const code = response.data.code;
      if (code !== 0) {
        if (code === 201) {
          logout();
        } else {
          message.error(response.data.msg);
        }
      }
    }
    return response;
  },
  (error) => {
    console.log(error, 'error');
    return Promise.reject(error);
  },
);

export default service;
